package cn.wang.service.sysadmin.Impl;

import cn.wang.dao.BaseDao;
import cn.wang.entity.sysadmin.Dept;
import cn.wang.service.sysadmin.DeptService;
import cn.wang.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by john on 2017/11/1.
 */
@Service("deptService")
@Transactional
public class DeptServiceImpl implements DeptService {
    @Autowired
    private BaseDao<Dept,String>baseDao;


    @Override
    public Pagination findPage(int pageNo, int pageSize) {


        return baseDao.pageByHql("from Dept",pageNo,pageSize);
    }

    @Override
    public List<Dept> findAll() {
        return baseDao.getListByHQL("from Dept");
    }

    @Override
    public void save(Dept dept) {
        baseDao.save(dept);
    }

    @Override
    public void update(Dept model) {
        baseDao.update(model);
    }

    @Override
    public Dept findById(String id) {
        return baseDao.get(Dept.class,id);
    }

    @Override
    public void delete(String[] ids) {
        //业务层放到service 保证在同一事务
        for (String id:ids) {
            baseDao.deleteById(Dept.class,id);
        }
    }
}
